import http from "@/api";
import { ResPage } from "@/api/interface";
import {
  ApiSysDictionaryCreate,
  ApiSysDictionaryDelete,
  ApiSysDictionaryGetOptions,
  ApiSysDictionaryGetString,
  ApiSysDictionarySearch,
  ApiSysDictionarySetString,
  ApiSysDictionaryUpdate
} from "@/api/apis/sys_dictionary";
import {
  dtoSysDictionaryCreate,
  dtoSysDictionaryDelete,
  dtoSysDictionaryInfo,
  dtoSysDictionaryUpdate
} from "@/api/dbdto/dtoSysDictionary";
import { ReqSearch } from "@/api/interface/Search/ReqSearch";
import { ReqGetDicOptions } from "@/api/interface/SysDictionary/ReqGetDicOptions";
import { ReqSysDictionaryGetString } from "@/api/interface/SysDictionary/ReqSysDictionaryGetString";
import { ReqSysDictionarySetString } from "@/api/interface/SysDictionary/ReqSysDictionarySetString";

export const requestSysDictionaryCreate = (params: dtoSysDictionaryCreate) => {
  return http.post(ApiSysDictionaryCreate, params);
};

export const requestSysDictionarySearch = (params: ReqSearch) => {
  return http.post<ResPage<dtoSysDictionaryInfo>>(ApiSysDictionarySearch, params);
};

export const requestSysDictionaryUpdate = (params: dtoSysDictionaryUpdate) => {
  return http.post(ApiSysDictionaryUpdate, params);
};

export const requestSysDictionaryDelete = (params: dtoSysDictionaryDelete) => {
  return http.post(ApiSysDictionaryDelete, params);
};

//获取字典值(string)
export const requestSysDicGetString = (k: string) => {
  return http.post(ApiSysDictionaryGetString, { dic_key_name: k } as ReqSysDictionaryGetString);
};

//设置字典值(string)
export const requestSysDicSetString = (k: string, v: string) => {
  return http.post(ApiSysDictionarySetString, { dic_key_name: k, dic_key_value: v } as ReqSysDictionarySetString);
};

//获取字典的key
export const requestSysDictionaryGetOptions = (key: string, searchText = "") => {
  if (key == "") {
    return;
  }
  let params: ReqGetDicOptions = {
    dic_key_name: key,
    search_text: searchText
  };
  return http.post(ApiSysDictionaryGetOptions, params);
};
